package com.tianji.learning.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.po.InteractionReply;
import com.tianji.learning.domain.query.ReplyPageQuery;
import com.tianji.learning.domain.vo.ReplyVO;
import com.tianji.learning.mapper.InteractionReplyMapper;
import com.tianji.learning.service.IInteractionReplyService;
import org.springframework.stereotype.Service;

// 互动问题的回答或评论 服务实现类
@Service
public class InteractionReplyServiceImpl extends ServiceImpl<InteractionReplyMapper, InteractionReply> implements IInteractionReplyService {

    @Override
    public PageDTO<ReplyVO> pageReplies(ReplyPageQuery replyPageQuery) {
        Page<InteractionReply> page = replyPageQuery.toMpPage();

        this.lambdaQuery()
                .eq(ObjectUtil.isNotNull(replyPageQuery.getQuestionId()), InteractionReply::getQuestionId, replyPageQuery.getQuestionId())
                .eq(ObjectUtil.isNotNull(replyPageQuery.getAnswerId()), InteractionReply::getAnswerId, replyPageQuery.getAnswerId())
                .page(page);

        return PageDTO.of(page, ReplyVO.class);
    }
}